#!/bin/bash
rm -rf ./tmp
mkdir ./tmp
unzip -o -d ./tmp "$1" &> /dev/null
./plist.b `pwd`/tmp/iTunesMetadata.plist
if [ $? -eq 0 ]; then
	echo "[x]:" $1
else
	plutil -i ./tmp/iTunesMetadata.plist -o /tmp/iTunesMetadata.plist &> /dev/null
	mv /tmp/iTunesMetadata.plist ./tmp/iTunesMetadata.plist
	./plist.b `pwd`/tmp/iTunesMetadata.plist
	if [ $? -eq 0 ]; then
		echo "[p]:" $1
	else
		echo "[n]:" $1
	fi
fi
cd ./tmp
zip -qr ./tmp.ipa ./*
cp ./tmp.ipa "$2/`basename \"$1\"`"
cd ..
rm -rf ./tmp
